class Word {
  final int? id;
  final String word;
  final String meaning;
  final String? example;
  final DateTime dateAdded;
  int reviewCount;
  DateTime lastReviewed;
  int? categoryId;
  String? categoryName;
  String? categoryColor;
  bool isRemembered;

  Word({
    this.id,
    required this.word,
    required this.meaning,
    this.example,
    DateTime? dateAdded,
    this.reviewCount = 0,
    DateTime? lastReviewed,
    this.categoryId,
    this.categoryName,
    this.categoryColor,
    this.isRemembered = false,
  })  : dateAdded = dateAdded ?? DateTime.now(),
        lastReviewed = lastReviewed ?? DateTime.now();

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'word': word,
      'meaning': meaning,
      'example': example,
      'dateAdded': dateAdded.toIso8601String(),
      'reviewCount': reviewCount,
      'lastReviewed': lastReviewed.toIso8601String(),
      'categoryId': categoryId,
      'categoryName': categoryName,
      'categoryColor': categoryColor,
      'isRemembered': isRemembered,
    };
  }

  factory Word.fromMap(Map<String, dynamic> map) {
    return Word(
      id: map['id'],
      word: map['word'],
      meaning: map['meaning'],
      example: map['example'],
      dateAdded: DateTime.parse(map['dateAdded']),
      reviewCount: map['reviewCount'],
      lastReviewed: DateTime.parse(map['lastReviewed']),
      categoryId: map['categoryId'],
      categoryName: map['categoryName'],
      categoryColor: map['categoryColor'],
      isRemembered: map['isRemembered'] ?? false,
    );
  }
}
